package cn.classyex.business.hr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import cn.classyex.business.hr.domain.RewardsPunishmentRecord;
import cn.classyex.business.hr.service.IRewardsPunishmentRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 奖惩记录管理Controller
 * 
 * @author yex
 * @date 2021-05-06
 */
@Controller
@RequestMapping("/hr/rewardsPunishmentRecord")
public class RewardsPunishmentRecordController extends BaseController
{
    private String prefix = "hr/rewardsPunishmentRecord";

    @Autowired
    private IRewardsPunishmentRecordService rewardsPunishmentRecordService;

    @RequiresPermissions("hr:rewardsPunishmentRecord:view")
    @GetMapping()
    public String rewardsPunishmentRecord()
    {
        return prefix + "/rewardsPunishmentRecord";
    }

    /**
     * 查询奖惩记录管理列表
     */
    @RequiresPermissions("hr:rewardsPunishmentRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RewardsPunishmentRecord rewardsPunishmentRecord)
    {
        startPage();
        List<RewardsPunishmentRecord> list = rewardsPunishmentRecordService.selectRewardsPunishmentRecordList(rewardsPunishmentRecord);
        return getDataTable(list);
    }

    /**
     * 导出奖惩记录管理列表
     */
    @RequiresPermissions("hr:rewardsPunishmentRecord:export")
    @Log(title = "奖惩记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RewardsPunishmentRecord rewardsPunishmentRecord)
    {
        List<RewardsPunishmentRecord> list = rewardsPunishmentRecordService.selectRewardsPunishmentRecordList(rewardsPunishmentRecord);
        ExcelUtil<RewardsPunishmentRecord> util = new ExcelUtil<RewardsPunishmentRecord>(RewardsPunishmentRecord.class);
        return util.exportExcel(list, "奖惩记录管理数据");
    }

    /**
     * 新增奖惩记录管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存奖惩记录管理
     */
    @RequiresPermissions("hr:rewardsPunishmentRecord:add")
    @Log(title = "奖惩记录管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RewardsPunishmentRecord rewardsPunishmentRecord)
    {
        return toAjax(rewardsPunishmentRecordService.insertRewardsPunishmentRecord(rewardsPunishmentRecord));
    }

    /**
     * 修改奖惩记录管理
     */
    @GetMapping("/edit/{rewardsPunishmentId}")
    public String edit(@PathVariable("rewardsPunishmentId") Long rewardsPunishmentId, ModelMap mmap)
    {
        RewardsPunishmentRecord rewardsPunishmentRecord = rewardsPunishmentRecordService.selectRewardsPunishmentRecordById(rewardsPunishmentId);
        mmap.put("rewardsPunishmentRecord", rewardsPunishmentRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存奖惩记录管理
     */
    @RequiresPermissions("hr:rewardsPunishmentRecord:edit")
    @Log(title = "奖惩记录管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RewardsPunishmentRecord rewardsPunishmentRecord)
    {
        return toAjax(rewardsPunishmentRecordService.updateRewardsPunishmentRecord(rewardsPunishmentRecord));
    }

    /**
     * 删除奖惩记录管理
     */
    @RequiresPermissions("hr:rewardsPunishmentRecord:remove")
    @Log(title = "奖惩记录管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rewardsPunishmentRecordService.deleteRewardsPunishmentRecordByIds(ids));
    }
}
